<template>
  <div class="common-layout">
    <el-container>
      <el-header class="header">
        <div class="logo">
          <img src="@/assets/vue.svg" alt="logo" />
          <span>Vue Admin</span>
        </div>
      </el-header>
      <el-container class="main-container">
        <el-aside width="200px" class="aside">
          <Aside />
        </el-aside>
        <el-container class="right-container">
          <el-main class="main-content">
            <h1>欢迎使用管理系统</h1>
            <el-card class="welcome-card">
              <template #header>
                <div class="card-header">
                  <span>系统信息</span>
                </div>
              </template>
              <div class="card-content">
                <p>当前版本：v1.0.0</p>
                <p>系统时间：{{ currentTime }}</p>
              </div>
            </el-card>
          </el-main>
          <el-footer class="footer">Footer © 2024</el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import Aside from '@/components/menu/aside.vue'
import { ref, onMounted, onUnmounted } from 'vue'

const currentTime = ref('')

const updateTime = () => {
  const now = new Date()
  currentTime.value = now.toLocaleString()
}

let timer = null

onMounted(() => {
  updateTime()
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style lang="less" scoped>
.common-layout {
  height: 100vh;
  width: 100%;
  overflow: hidden;
  
  .el-container {
    height: 100%;
  }

  .header {
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 60px;
    position: fixed;
    width: 100%;
    z-index: 1000;

    .logo {
      display: flex;
      align-items: center;
      
      img {
        width: 40px;
        height: 40px;
        margin-right: 10px;
      }

      span {
        font-size: 20px;
        font-weight: bold;
      }
    }
  }

  .main-container {
    margin-top: 60px;
    height: calc(100vh - 60px);
  }

  .aside {
    background-color: #545c64;
    height: 100%;
    position: fixed;
    left: 0;
    top: 60px;
  }

  .right-container {
    margin-left: 200px;
    height: 100%;
  }

  .main-content {
    padding: 20px;
    background-color: #f5f7fa;
    min-height: calc(100vh - 120px);

    h1 {
      margin-bottom: 20px;
      color: #303133;
    }

    .welcome-card {
      max-width: 600px;
      margin: 0 auto;

      .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .card-content {
        p {
          margin: 10px 0;
          color: #606266;
        }
      }
    }
  }

  .footer {
    text-align: center;
    line-height: 60px;
    color: #909399;
    background-color: #fff;
    height: 60px;
  }
}
</style>